<?php
/**
 * Dependency abstract file source
 *
 * PHP version 5
 *
 * @category  W
 * @package   Services
 * @author    Olivier Hoareau <olivier@phppro.fr>
 * @copyright 2009 PHPPRO http://www.phppro.fr
 * @license   http://dev.phppro.fr/license PHPPRO
 * @version   SVN: $Id:$
 * @link      http://dev.phppro.fr/projects/wdependency
 */
require_once 'W/W.php';
require_once 'W/Dependency/Source/Abstract.php';
/**
 * Dependency abstract file source
 *
 * @category  W
 * @package   Services
 * @author    Olivier Hoareau <olivier@phppro.fr>
 * @copyright 2009 PHPPRO http://www.phppro.fr
 * @license   http://dev.phppro.fr/license PHPPRO
 * @version   SVN: $Id$
 * @link      http://dev.phppro.fr/projects/wdependency
 */
abstract class W_Dependency_Source_File_Abstract extends W_Dependency_Source_Abstract
{
    private $file;

    public function setFile($file)
    {
        $this->file = $file;
        return $this;
    }
    public function import($options=null)
    {
        if (null === $this->file) {
            throw new RuntimeException('No source file set');
        }
        if (false === W_W::fs()->isExistingFile($this->file)) {
            throw new RuntimeException("Source file '{$this->file}' does not exist or is not readable");
        }
        return $this->parseFile($this->file);
    }
    public function parseFile($file)
    {
        return $this->parse(W_W::fs()->read($this->file));
    }
    public function parse($data)
    {
        return $data;
    }
}